<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jq-1.12.4.js"></script>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: blue;
        }

        .red {
            background-color: red;
        }
    </style>
    <script>
        $(function () {
            $(".btn").click(function () {
                //如果有类样式就移除removeClass("red")，如果没有就添加addClass("red")
                $("#app").toggleClass('red')
            })
        })
    </script>
</head>

<body>
    <button class="btn">toggle</button>
    <div id="app"></div>
</body>

</html>